package com.micro.ai.commons.exception;

import com.micro.ai.commons.constant.ErrorCodeEnum;
import lombok.Getter;

/**
 * 全局异常基类
 * 
 * @author micro-ai
 * @since 0.0.1
 */
@Getter
public class GlobalException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private final String code;

    /**
     * 错误信息
     */
    private final String message;

    /**
     * 错误数据
     */
    private final Object data;

    /**
     * 构造函数
     */
    public GlobalException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
        this.data = null;
    }

    /**
     * 构造函数
     */
    public GlobalException(String code, String message, Object data) {
        super(message);
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 构造函数
     */
    public GlobalException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.data = null;
    }

    /**
     * 构造函数
     */
    public GlobalException(String code, String message, Object data, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 构造函数 - 使用错误码枚举
     */
    public GlobalException(ErrorCodeEnum errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = null;
    }

    /**
     * 构造函数 - 使用错误码枚举带数据
     */
    public GlobalException(ErrorCodeEnum errorCode, Object data) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = data;
    }

    /**
     * 构造函数 - 使用错误码枚举带原因
     */
    public GlobalException(ErrorCodeEnum errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = null;
    }

    /**
     * 构造函数 - 使用错误码枚举带数据和原因
     */
    public GlobalException(ErrorCodeEnum errorCode, Object data, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = data;
    }
}
